#https://www.youtube.com/watch?v=4haMUvUxUJI
import socket

PORT = 5012
HOST = "localhost"
URLS = {
    "/": "Home Page",
    "/blog": "Blog Page"
}
ERRORS = {
    "404": "Method not allowed",
    "405": "Not Found"
}

def parse_request(request):
    parsed = request.split(" ")
    method = parsed[0]
    url = parsed[1]
    return (method, url)

def generate_headers(method, url):
    header_template = "HTTP/1.1 {} {}\n\n"
    if not method == "GET":
        # так нельзя делать. Если это будет рендериться на странице
        return (f"HTTP/1.1 405 Method {method} not allowed\n\n", 405)

    if not url in URLS:
        return ("HTTP/1.1 404 Resorce [{url}] Not found\n\n", 404)

    return ("HTTP/1.1 200 OK\n\n", 200)

def generate_content(code, url):
    if code == 404:
        

def generate_response(request):
    method, url = parse_request(request)
    headers, code = generate_headers(method, url)
    body = gener
    return (headers + body).encode()

def run():
    server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    server_socket.bind((HOST, PORT))
    server_socket.listen()
    
    while True:
        client_socket, addr = server_socket.accept()
        request = client_socket.recv(1024)
        print(addr)
        print(request.decode("utf-8"))
        print()
        
        response = generate_response(request.decode("utf-8"))
        
        client_socket.sendall(response)
        client_socket.close()

if __name__ == "__main__":
    print(f"Server running on http://{HOST}:{PORT}")
    run()
